<template>
  <div class="waiting">
    <span class="tips">登录中...</span>
  </div>
</template>

<script>
import { login } from '@/api/user'
import cacheUtil from '@/utils/cache'

export default {
  name: 'LoginFrom',
  mounted() {
    this.doLogin()
  },
  methods: {
    doLogin() {
      login({
        loginName: 'homepage',
        loginPassword: 'SG9tZVBhZ2UxMjM0NTY='
      }).then((res) => {
        if (res.success) {
          if (!res.data.moduleTree) {
            this.$message.error(
              '该用户无菜单模块权限，无法登录！'
            )
            return
          }
          cacheUtil.setItem(
            'menu',
            JSON.stringify(res.data.moduleTree)
          )
          cacheUtil.setItem('token', res.data.token)
          cacheUtil.setItem('userName', res.data.userName)
          cacheUtil.setItem('deptName', res.data.deptName)
          cacheUtil.setItem('status', res.data.userLevel)
          this.$router.replace(`/${this.$route.query.to}`)
        } else {
          this.$message.error(res.message)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.waiting {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;

  .tips {
    color: #333;
    font-size: 30px;
  }
}
</style>
